﻿using LXYYY.DTO;
using LXYYY.GoodsDTO;
using LXYYY.IGoodsService;
using LXYYY.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace LXYYY.GoodsService
{
    public class GoodsInfoImgService : ApplicationService, IGoodsInfoImgService
    {
        private readonly IRepository<MyGoodsInformation, int> _Information;
        private readonly IRepository<MyGoodsImg, int> _Img;
        private readonly IRepository<MyGoodsType, int> _Types;
        private readonly IRepository<MyGoodsInventory, int> _Inventory;
        private readonly IRepository<MyGoodsSpecifications, int> _Specifications;
        
        public GoodsInfoImgService(
            IRepository<MyGoodsInformation, int> Information, 
            IRepository<MyGoodsImg, int> Img, 
            IRepository<MyGoodsType, int> Types, 
            IRepository<MyGoodsInventory, int> Inventory,
            IRepository<MyGoodsSpecifications, int> Specifications
            )
        {
            _Information = Information;
            _Img = Img;
            _Types = Types;
            _Inventory = Inventory;
            _Specifications = Specifications;
        }
        [HttpGet,Route("GoodsInfoTypes")]
        public async Task<List<GoodInfoTypeDTO>> GoodsInfoTypes(int ids)
        {
            var infolist = await _Information.GetListAsync();
            var typelist = await _Types.GetListAsync();
            var list = (from s in infolist
                       join t in typelist on s.InformationTypeId equals t.Id 
                        select new GoodInfoTypeDTO()
                       {
                            GoodsId=s.Id,
                           InformationTypeId = s.InformationTypeId,
                           GoodsTypeAlias = t.GoodsTypeAlias,
                           GoodsTypeDisplay = t.GoodsTypeDisplay,
                           GoodsTypeName = t.GoodsTypeName,
                           GoodsTypeOrder = t.GoodsTypeOrder,
                           GoodsTypeParentId = t.GoodsTypeParentId,
                           InformationBorwseNum = s.InformationBorwseNum,
                           InformationDetaile = s.InformationDetaile,
                           InformationDisplay = s.InformationDisplay,
                           InformationEvaluaNum = s.InformationEvaluaNum,
                           InformationFreight = s.InformationFreight,
                           InformationName = s.InformationName,
                           InformationSaleBegin = s.InformationSaleBegin,
                           InformationSaleNum = s.InformationSaleNum,
                           InformationSalePrice = s.InformationSalePrice,
                           InformationSpecild = s.InformationSpecild,
                           InformationSPromotion = s.InformationSPromotion,
                           InformationStata = s.InformationStata,
                           InformationWeight = s.InformationWeight,
                           MyProperty = s.MyProperty,
                           
                       }).ToList();
            var slist = list.Where(x => x.InformationTypeId == ids).ToList();
            return slist;
        }
        //商品详情
        [HttpGet,Route("GoodsEdit")]
        public async  Task<GoodInfoTypeDTO> GoodsEdit(int ids)
        {
            var infolist = await _Information.GetListAsync();
            var Inventorylist = await _Inventory.GetListAsync();
            var list = (from s in infolist
                        join i in Inventorylist on s.InformationDisplay equals i.Id
                        select new GoodInfoTypeDTO()
                        {
                            GoodsId = s.Id,
                            InformationBorwseNum = s.InformationBorwseNum,
                            InformationDetaile = s.InformationDetaile,
                            InformationDisplay = s.InformationDisplay,
                            InformationEvaluaNum = s.InformationEvaluaNum,
                            InformationFreight = s.InformationFreight,
                            InformationName = s.InformationName,
                            InformationSaleBegin = s.InformationSaleBegin,
                            InformationSaleNum = s.InformationSaleNum,
                            InformationSalePrice = s.InformationSalePrice,
                            InformationSpecild = s.InformationSpecild,
                            InformationSPromotion = s.InformationSPromotion,
                            InformationStata = s.InformationStata,
                            InformationWeight = s.InformationWeight,
                            MyProperty = s.MyProperty,
                            InventoryNumber = i.InventoryNumber,
                            InventoryPrice = i.InventoryPrice
                        }).ToList();
            var slist = list.Where(x => x.GoodsId == ids).FirstOrDefault();
            return slist;
        }
        [HttpGet,Route("GoodsSKU")]
        public async Task<List<MyGoodsSpecificationsShowDTO>> GoodsSKU(int id)
        {
            var skulist = await _Specifications.GetListAsync();
            var list = (from s in skulist
                        where s.SpecificationsTypeId == id
                        select new MyGoodsSpecificationsShowDTO()
                        {
                            Id = s.Id,
                            SpecificationsTypeId = s.SpecificationsTypeId,
                            SpecificationsDIsplay = s.SpecificationsDIsplay,
                            SpecificationsName = s.SpecificationsName,
                            SpecificationsOrder = s.SpecificationsOrder
                        }).ToList();
            
            return list;
        }
    }
}
